package com.wlstock.funi.model;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

import java.lang.reflect.Field;
import java.util.Date;

@DatabaseTable
public class PositionModel extends BaseModel{

	public static final String ME = "ME" ;

	@DatabaseField (id = true)
	private int id = 1;//默认id 永远只有一条
	@DatabaseField
	private String owner;//持有者
	@DatabaseField
	private float  stockMoney;//持仓总值,包含了天天理财以及基金等,所以不能用这个
	@DatabaseField
	private float  totalAsserts = -1f;//总资产
	@DatabaseField
	private float useableFund = -1f;//可用资金
	@DatabaseField
	private float curPostion = -1f ;//当前仓位

	@DatabaseField
	private Date  lastUpdate = new Date();


	
//	private PositionModel(){}
//	
//	public PositionModel(float curPosition){
//		this();
//		this.curPostion = curPosition;
//	}
	
	public String getOwner() {
		return owner;
	}
	public void setOwner(String owner) {
		this.owner = owner;
	}
	public float getStockMoney() {
		return stockMoney;
	}
	public void setStockMoney(float stockMoney) {
		this.stockMoney = stockMoney;
	}
	public float getTotalAsserts() {
		return totalAsserts;
	}
	public void setTotalAsserts(float totalAsserts) {
		this.totalAsserts = totalAsserts;
	}
	public float getUseableFund() {
		return useableFund;
	}
	public void setUseableFund(float useableFund) {
		this.useableFund = useableFund;
	}
	public float getCurPostion() {
		if (curPostion != -1)
			return curPostion;
		else if(useableFund != -1 && totalAsserts != -1){
			return  1 - useableFund/totalAsserts;
		}else{
			return 0;
		}
	}
	public void setCurPostion(float curPostion) {
		this.curPostion = curPostion;
	}
	
	@Override
	public String toString() {
		Field[] fields = this.getClass().getDeclaredFields();
		String values = "";
		try {
			for (int i = 0; i < fields.length; i++) {
				fields[i].setAccessible(true);
				values = fields[i].getName() + " = " +fields[i].get(this).toString() +" ,";
			}
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		}
		return values;
	}


	public Date getLastUpdate() {
		return lastUpdate;
	}

	public void setLastUpdate(Date lastUpdate) {
		this.lastUpdate = lastUpdate;
	}

}
